<template>
  <div class="form-wrap">
    <div class="clearfix title">
      <span class="h3">角色</span>
      {{ title }}
    </div>
    <!--<keep-alive >-->
    <router-view
      :exportable="true"
      :table-title="tableTitle"
      :table-data="tableData"
      :create-path="createPath"
      :get-table-list="getTableList"
      :deletable="true"
      @childTitle="childTitle"
      @edit="edit"
      @del="del"
      @selectionChange="selectionChange"/>
      <!--</keep-alive>-->
  </div>
</template>

<script>

export default {
  data() {
    return {
      title: '',
      createPath: 'system_manage.role.create',
      tableTitle: [
        {
          cn: 'id',
          en: 'id'
        },
        {
          cn: '标识',
          en: 'slug'
        },
        {
          cn: '名称',
          en: 'name'
        },
        {
          cn: '创建时间',
          en: 'created_at'
        },
        {
          cn: '更新时间',
          en: 'updated_at'
        }
      ],
      tableData: [
        // {
        //     id:1,
        //     slug:'admin',
        //     name:'系统管理员',
        //     created_at:'2017-12-27 13:48:47',
        //     updated_at:'2017-12-27 13:48:47',
        // },
      ],

      arrMenu: [],
      arrPermissions: []
    }
  },
  methods: {

    getTableList(data, pageInfo) {
      const loading = this.$loading()

      this.$get('action/PositionCtrl/dataGrid', data).then(res => {
        console.log(res)
        const list = res.data.list
        // let arrMenu = res.arrMenu;
        // let arrPermissions = res.arrPermissions;
        pageInfo.totalPage = res.data.totalPage
        pageInfo.totalRow = res.data.totalRow

        this.tableData = list
        loading.close()
        // this.arrMenu = arrMenu;
        // this.arrPermissions = arrPermissions;
      })
        .catch(_=>{
          loading.close()
        })
    },

    del(val) {
      console.log(this)
      const data = { id: val.row.id }
      this.$post('action/PositionCtrl/del', data)
        .then(res => {

        })
    },
    selectionChange(val) {
      console.log(val)
    },
    childTitle(val) {
      this.title = val
    },
    edit(val) {
      console.log(val)
      this.$router.push({
        name: 'system_manage.role.edit',
        query: {
          id: val.row.id
        },
        params: {
          details: val.row
        }
      })
    }
  }
}
</script>

<style scoped rel="stylesheet/scss" lang="scss">
    .form-wrap{
        padding:0 15px;
        .title{
            padding: 15px 0;
        }
    }
</style>
